class CarFactory:
    """工厂只需要一个"""
    __obj = None
    __init_flag = True

    def __new__(cls,*args,**kwargs):
        if cls.__obj == None:
            cls.__obj = super().__new__(cls)

        return cls.__obj

    def __init__(self):
        if CarFactory.__init_flag:
            print('init....')
            CarFactory.__init_flag = False
        

    def createCar(self,brand):
        if brand == "奔驰":
            return Benz()
        elif brand == "宝马":
            return BMW()
        elif brand == "比亚迪":
            return BYD()
        else:
            return "未知品牌,不能创建"


class Benz:
    pass

class BMW:
    pass

class BYD:
    pass


f  = CarFactory()
c1 = f.createCar("奔驰")
c2 = f.createCar("宝马")
print(c1)
print(c2)

f1 = CarFactory()
print('f:',f,id(f))
print('f1:',f1,id(f1))